package com.project.frba.bi.queueing;

import java.util.List;

import org.springframework.context.ApplicationContext;

import com.project.frba.bi.BiUtil;
import com.project.frba.bi.descriptor.Descriptor;
import com.project.frba.bifront.client.model.Cube;
import com.project.frba.bifront.client.model.Filter;

public class CubeMediator {
	
		
	public static List<String> getValuesForProperty(Descriptor descriptor, String propertyName){
		OlapQueryBuilder queryBuilder = new OlapQueryBuilder(descriptor);
		String query = queryBuilder.getAllPropertyValues(propertyName);
		System.out.println(query);
		ApplicationContext context = BiUtil.getApplicationContext();
		OlapDAO dao = (OlapDAO)context.getBean("olapDao");
		
		return dao.getValuesForProperty(query, descriptor.getPropertyByName(propertyName).getType());
	}

	public static Cube getDataWithSpring(Descriptor descriptor, List<String> allProps, List<Filter> filters) {
		OlapQueryBuilder queryBuilder = new OlapQueryBuilder(descriptor);
		String query = queryBuilder.getCubeQuery(allProps, filters);
		
		ApplicationContext context = BiUtil.getApplicationContext();
		OlapDAO dao = (OlapDAO)context.getBean("olapDao");
		
		return dao.getData(query, allProps, descriptor);
	}

}
